package utils;

import java.util.ArrayList;

import javax.swing.JOptionPane;

import model.DATAError;

public class MessageHandler {
	private static MessageHandler messageHandeler;
	private static ArrayList<DATAError> errors;

	public static ArrayList<DATAError> getErrors() {
		return errors;
	}

	private MessageHandler() {

		if (errors == null) {
			errors = new ArrayList<DATAError>();

		}
	}

	public static MessageHandler getMessageHandler() {
		if (messageHandeler == null) {
			messageHandeler = new MessageHandler();
		}
		return messageHandeler;
	}

	public void ShowErrors() {
		for (DATAError err : errors) {
			JOptionPane.showMessageDialog(null, err.getErrorText(),
					err.getErrorName(), JOptionPane.ERROR_MESSAGE);
		}
	}

	public static void showSingleError(String texterror) {
		MessageHandler.getMessageHandler().getErrors()
				.add(new DATAError("Error", texterror));
		MessageHandler.getMessageHandler().ShowErrors();
	}
}
